package com.lishu.carsafe.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.lishu.carsafe.R;
import com.lishu.carsafe.adapter.MonitorAdapter;
import com.lishu.carsafe.http.HttpBase;
import com.lishu.carsafe.http.HttpLoader;
import com.lishu.carsafe.model.BaseModel;
import com.lishu.carsafe.model.MonitorListModel;
import com.lishu.carsafe.utils.ToastUtil;

import java.util.List;

public class MonitorActivity extends BaseActivity{
    private RecyclerView rv_view;
    private MonitorAdapter adapter;
    private List<MonitorListModel.MonitorBean> list;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_monitor);

        initView();
        initEvent();
        initData();
    }

    private void initData() {
        adapter = new MonitorAdapter(this);
        rv_view.setLayoutManager(new LinearLayoutManager(this));
        rv_view.setAdapter(adapter);
        getMonitorList();
    }

    private void initView() {
        setTopTitle(R.string.module_monitor);
        rv_view = findViewById(R.id.rv_view);
    }

    private void initEvent() {
    }

    /**
     * 获取运营监测列表
     */
    private void getMonitorList(){
        showAlways("正在加载数据，请稍等");
        HttpLoader.getMonitorList(new HttpBase.IResponseListener(){
            @Override
            public void onResponse(BaseModel model) {
                hide();
                if (model == null) {
                    ToastUtil.showShort(R.string.please_check_network);
                    return;
                }
                if (!model.success()) {
                    ToastUtil.showShort(getString(R.string.get_data_fail) + model.getMsg());
                    return;
                }
                list = ((MonitorListModel)model).getData();
                //更新数据
                adapter.setList(list);
            }
        });
    }
}
